﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using dataSendModel.Util;
using DevComponents.DotNetBar;
using System.Runtime.InteropServices;

namespace dataSend
{
    public partial class SendForm : DevComponents.DotNetBar.Office2007Form
    {
        private string devId = "";
        private MainForm mf = null;
        private short iType = 0;
        public SendForm(string devId,short iType, MainForm mf)
        {
            InitializeComponent();
            this.devId = devId;
            this.mf = mf;
            this.iType = iType;
        }

        //发送
        private void btnSendMsg_Click(object sender, EventArgs e)
        {
            if (tbContent.Text.Equals(string.Empty) && tbContent.Text.Length==0)
            {
                MessageBoxEx.Show("内容不能为空", "系统提示！");
                return;
            }
            short result = 0;
            try
            {
                if (iType == 0)
                {
                    result = mf.vsOcx.SendComTransmitMsgEx(devId, short.Parse("0"), tbContent.Text, short.Parse(tbContent.Text.Length.ToString()));
                }
                else
                {
                    byte[] csByte = { 0x5a, 0xa5, 0x23, 0x45, 0x65, 0x01, 0x00, 0x03, 0x01, 0x01, 0x00, 0x00, 0x01, 0xaf, 0xac };
                    //result = mf.vsOcx.SendComTransmitMsgEx1(devId, short.Parse("1"), csByte, short.Parse(csByte.Length.ToString()));
                    result = mf.vsOcx.SendComTransmitMsgEx(devId, short.Parse("1"), tbContent.Text, short.Parse(tbContent.Text.Length.ToString()));
                }

                if (result >= 0)
                {
                    MessageBoxEx.Show("发送成功", "系统提示！");
                }
                else
                {
                    MessageBoxEx.Show("发送失败", "系统提示！");
                }
            }
            catch (Exception)
            {

                throw;
            }
        }

        //取消
        private void btnCancelSendMsg_Click(object sender, EventArgs e)
        {
            this.tbContent.Text = string.Empty;
            this.Close();
        }
    }
}
